package com.aceitunaproject.server;

import java.io.Serializable;
import java.util.Properties;

import com.aceitunaproject.server.player.Player;
import com.aceitunaproject.server.player.PlayerManager;
import com.sun.sgs.app.AppContext;
import com.sun.sgs.app.AppListener;
import com.sun.sgs.app.ClientSession;
import com.sun.sgs.app.ClientSessionListener;

/**
 * Application listener for handling user logins and application
 * initialization.
 * 
 * @author Maciej Miechowicz
 */
public class AceitunaAppListener implements AppListener, Serializable {

	private static final long serialVersionUID = -907468195733550481L;

	/**
	 * Handles application initialization
	 * 
	 * @param props application properties
	 */
	@Override
	public void initialize(Properties props) {
	}

	/**
	 * Handles user login
	 * 
	 * @param session user session
	 */
	@Override
	public ClientSessionListener loggedIn(ClientSession session) {
		Player player = AppContext.getManager(PlayerManager.class).getPlayer(session);
		
		// set player session
		player.setSession(session);
		
		return player;
	}

}
